﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using OpenTK;
using CastleOfTheDisillusioned.Location;

namespace CastleOfTheDisillusioned {
	abstract class Entity : BoundingBox {

		public virtual void Draw() {

		}

		public virtual void Update() {

		}

		protected Vector2d Move(double XDiff, double YDiff) {
			double Precision = 1.0 / 32.0;
			Vector2d Diff = new Vector2d(0, 0);
			if (XDiff != 0) {
				if (Location_State.CurrentMap.PlaceFree(this, X + XDiff, Y)) {
					X += XDiff;
					Diff.X += XDiff;
				} else {
					int sign = Math.Sign(XDiff);
					for (double i = 0; i < Math.Abs(XDiff); i += Precision) {
						if (Location_State.CurrentMap.PlaceFree(this, X + sign, Y)) {
							X += sign;
							Diff.X += sign;
						} else {
							break;
						}
					}
				}
			}

			if (YDiff != 0) {
				if (Location_State.CurrentMap.PlaceFree(this, X, Y + YDiff)) {
					Y += YDiff;
					Diff.Y += YDiff;
				} else {
					int sign = Math.Sign(YDiff);
					for (double i = 0; i < Math.Abs(YDiff); i += Precision) {
						if (Location_State.CurrentMap.PlaceFree(this, X, Y + sign)) {
							Y += sign;
							Diff.Y += sign;
						} else {
							break;
						}
					}
				}
			}
			return Diff;
		}
	}
}
